<?php
namespace Admin\Controller;
class UserRecordController extends CommonController{
    public function _initialize() {
		parent::_initialize();
        $this->_mod = D('UserRecord');
    }

    public function _before_index() {
		$this->list_relation = true;
        $this->_exclude = 'edit';
        $this->options = $this->check();
        $p = I('p',1,'intval');
        $this->assign('p',$p);

        $this->assign('list_table',true);
    }

    public function index(){
        $page  = I('get.p',1,'int');
        $obj = D("UserRecord as ur");
        $fex = C('DB_PREFIX');
        $map = $this->_search();
        $pagesize = 20;
        $count = $obj->join('left join '.$fex.'user as u on u.id = ur.user_id')
            ->where($map)->count();
        $pageObj = new \Org\Yike\Page($count,$pagesize);
        $lists = $obj->join('left join '.$fex.'user as u on u.id = ur.user_id')
                     -> field('ur.*,u.username')
                     -> where($map)
                     -> order('ur.option_time desc')
                     -> page($page,$pageObj->listRows)
                     -> select();
        $this->assign('list',$lists);
        $this->assign('page',$pageObj->show());
        $this->display();
    }

    protected function _search() {
        $map = array();
        $type = I('get.type',1,'int');
        $map['ur.type'] = $type;
       ($keyword = I('get.keyword')) && $map['u.username|u.email'] = array('like', '%'.$keyword.'%');

        $this->assign('search', array(

            'keyword' => $keyword,
        ));
        $this->assign('type',$type);
        return $map;
    }

}